package com.lyb.controller;

import com.lyb.Dto.RolePermissionDto;
import com.lyb.common.AjaxResult;
import com.lyb.pojo.Role;
import com.lyb.services.impl.RoleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
public class RoleC {
    @Autowired
    RoleServiceImpl roleService;
    @PostMapping("/update")
    public AjaxResult update(@RequestBody Role role){
        roleService.update(role);
        return AjaxResult.success("操作成功");
    }
    @DeleteMapping("/del")
    public AjaxResult del(Long id){
        roleService.del(id);
        return AjaxResult.success("操作成功");
    }
    @GetMapping("/queryPage")
    public AjaxResult queryPage(Integer pageSize, Integer pageNum){
        return AjaxResult.success(roleService.queryPage(pageSize,pageNum));
    }
    @PostMapping("/add")
//    public AjaxResult add(@RequestBody Role role){
//        roleService.add(role);
//        return AjaxResult.success("操作成功");
//    }
    public AjaxResult add(@RequestBody RolePermissionDto rolePermissionDto){
        roleService.add(rolePermissionDto);
        return AjaxResult.success("操作成功");
    }
    @GetMapping("/findByRoleId")
    public AjaxResult findByRoleId(Long id){
        return AjaxResult.success(roleService.findByRoleId(id));
    }
}
